

package study.algorithm.search;

import java.util.ArrayList;

public class BasicSearch_demo1 {
    public BasicSearch_demo1() {
    }

    public static void main(String[] args) {
        int[] arr = new int[]{63, 57, 43, 32, 78, 43, 56, 44, 222, 674, 35, 43};
        int num = 43;
        System.out.println(basicSearch(arr, num));
        System.out.println(basicSearch_1(arr, num));
        System.out.println(basicSearch_2(arr, num));
    }

    public static boolean basicSearch(int[] arr, int num) {
        for(int j : arr) {
            if (j == num) {
                return true;
            }
        }

        return false;
    }

    public static int basicSearch_1(int[] arr, int num) {
        for(int i = 0; i < arr.length; ++i) {
            if (arr[i] == num) {
                return i;
            }
        }

        return -1;
    }

    public static ArrayList<Integer> basicSearch_2(int[] arr, int num) {
        ArrayList<Integer> list = new ArrayList();

        for(int i = 0; i < arr.length; ++i) {
            if (arr[i] == num) {
                list.add(i);
            }
        }

        return list;
    }
}
